const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_name: '',
    password: '',
    use: '',
    pwd: "",
    audit_tips: 2,
    show: false,
    store_id: ""
  },
  singin_user() {
    this.setData({
      show: true
    })
  },

  dialog_confirm() {
    let that = this
    app.request("/user/addStoreUser", {
      method: "post",
      data: {
        phone: that.data.use,
        password: that.data.pwd,
        store_id: that.data.store_id
      }
    }).then(res => {
      console.log(res);
    })
  },
// 获取审核状态
  get_audit() {
    app.request("/user/check_userstore", {}).then(res => {
      console.log(res, "audit");
      this.setData({
        audit_tips: res.data.data,
        store_id: res.data.store_id
      })
    })
  },
   /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this
    console.log(res, '88888888888888888888')
    if (res.from === 'button') {
      console.log("来自页面内转发按钮");
      console.log(res.target);
    } else {
      var pages = getCurrentPages() //获取加载的页面
      var currentPage = pages[pages.length-1] //获取当前页面的对象
      var url = currentPage.route //当前页面url
      console.log(url,'888888888888')
      console.log("来自右上角转发菜单")
      return {
         title:  '分享至朋友圈',
         path: url,
        success: (res) => {
          console.log("转发成功", res);
        },
        fail: (res) => {
          console.log("转发失败", res);
        }
      }
    }

  },
// 商家登录
  login() {
    let {
      user_name,
      password
    } = this.data
    app.request('/user/StoreLogin', {
      method: "POST",
      data: {
        phone: user_name,
        password: password
      }
    }).then(res => {
      console.log(res, "商家登录");
      if (res.data.code == 200) {
        let c_date= new Date()
        wx.setStorageSync('api_token', res.data.api_token)
        wx.setStorageSync('c_date', c_date)
        let {
          title,
          uid
        } = res.data.store_info
        let shop_data = {
          title,
          uid
        }
        wx.setStorageSync('shop_data', shop_data)
        wx.redirectTo({
          url: `/pages/shop_info/shop_info`,
        })
      }else{
        wx.showToast({
          title: res.data.msg,
          icon:"none"
        })
      }
    })
  },

// 注册
  singin() {
    let audit_tips = this.data.audit_tips
    if (!audit_tips) {
      wx.navigateTo({
        url: '/pages/Merchant/Merchant',
      })
    }

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_audit()
    wx.showShareMenu({
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log(res)
      },
      fail(e) {
        console.log(e)
      }
    })
  },

  onShow: function () {
    this.get_audit()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})